package wangbaguanlixitong.servlet;

import wangbaguanlixitong.dao.HyDao;
import wangbaguanlixitong.model.Hy;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet(name = "UpdateServlet",urlPatterns = "/updatehy")
public class HYUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        HyDao hydao = new HyDao();
        Hy hy = null;
        try {

            hy = hydao.getHyByName(request.getParameter("name"));


        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }


            String card =request.getParameter("card");
            String idcard =request.getParameter("idcard");
            String sex =request.getParameter("sex");
            String age =request.getParameter("age");
            String tel =request.getParameter("tel");
            String yuan =request.getParameter("yuan");



        hy.setCard(card);
       // hy.setName(name);
        hy.setIdcard(idcard);
        hy.setSex(sex);
        hy.setAge(age);
        hy.setTel(tel);
        hy.setYuan(yuan);

        hydao.uphuiyuan(hy);

        request.getRequestDispatcher("lookhuiyuan.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
